# -*- coding: utf-8 -*-
import os
import pandas as pd
from Django_Admin.settings import BASE_DIR


def ReadCsv(filename):
    # 存放扩展信息的文件所在的文件夹wjj
    # path_wjj = '../../../config/extendInfo'
    path_wjj = BASE_DIR + '/config/extendInfo'
    # print('path', path_wjj)
    dataframe_dict = {}
    fileList = os.listdir(path_wjj)  # 列出文件夹下所有的目录与文件
    # print('当前目录下的所有文件：',fileList)
    for item in fileList:
        path = os.path.join(path_wjj, item)
        # print('当前path：',path,os.path.isfile(path),item.split('.')[0])
        if os.path.isfile(path) and item.split('.')[0] == filename:
            try:
                # 适用于发邮件，excal的格式
                # dataframe_dict[item[:-4]] = pd.read_csv(path, keep_default_na=False, encoding='utf-8', header=None,
                #                                         error_bad_lines=False, index_col=None)
                with open(path, 'rb') as f:
                    # 读取出来的文本内容
                    content = f.read()
                # 换行不用去掉，后面要用
                # content = content.replace('\n\t','')
                dataframe_dict[item[:-4]] = content
            except Exception as ex:
                print(ex)
    return dataframe_dict

# r = ReadCsv('config_ctp')
# print(r)
